<div>
    <form class="form-horizontal bv-form"  role="form"  id="updateForm">
        <input type="hidden" name="adv_id" value="{$data.adv_id}">
        <input type="hidden" id="acity" value="{$data.adv_city}">
        <input type="hidden" id="adistrict" value="{$data.adv_district}">
        <fieldset>
            <legend>基本信息</legend>
            <div class="form-group">
                <label class="col-sm-3 control-label">广告投放方式</label>
                <div class="col-sm-5">
                    <select class="SearchForm form-control" name="style" id="style" style="width:200px;height:32px;">
                        <option value="1" {eq name='$data.adv_style' value="1"}selected{/eq}>普通投放</option>
                        <option value="2" {eq name='$data.adv_style' value="2"}selected{/eq}>置顶轮播</option>
                    </select>
                </div>
            </div>
            <div class="form-group place" style="display:none">
                <label class="col-sm-3 control-label">广告投放地区</label>
                <div class="col-sm-5">
                    <select class="SearchForm form-control" name="region" id="region" style="width:200px;height:32px;">
                        <option value="1" {eq name='$data.adv_range' value="1"}selected{/eq}>全国</option>
                        <option value="2" {eq name='$data.adv_range' value="2"}selected{/eq}>本地</option>
                    </select>
                </div>
            </div>
            <div class="form-group drop" style="display:none">
                <label class="col-sm-3 control-label">省</label>
                <div class="col-sm-5">
                    <select class="SearchForm form-control" id="province" name="province" style="width:200px;height:32px;">
                        <option value="">不限</option>
                    </select>
                </div>
            </div>
            <div class="form-group drop" style="display:none">
                <label class="col-sm-3 control-label">市</label>
                <div class="col-sm-5">
                    <select class="SearchForm form-control" id="city" name="city" style="width:200px;height:32px;">
                        <option value="">不限</option>
                    </select>
                </div>
            </div>
            <div class="form-group drop" style="display:none">
                <label class="col-sm-3 control-label">区</label>
                <div class="col-sm-5">
                    <select class="SearchForm form-control" id="area" name="area" style="width:200px;height:32px;">
                        <option value="">不限</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">目标用户性别</label>
                <div class="col-sm-5">
                    <select class="SearchForm form-control" name="sex" style="width:200px;height:32px;">
                        <option value="1" {eq name='$data.adv_gender' value="1"}selected{/eq}>男</option>
                        <option value="2" {eq name='$data.adv_gender' value="2"}selected{/eq}>女</option>
                        <option value="3" {eq name='$data.adv_gender' value="3"}selected{/eq}>全部</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">目标用户年龄段</label>
                <div class="col-sm-5">
                    <select class="SearchForm form-control" name="age" style="width:200px;height:32px;">
                        <option value="1" {eq name='$data.adv_age' value="1"}selected{/eq}>0-18</option>
                        <option value="2" {eq name='$data.adv_age' value="2"}selected{/eq}>19-55</option>
                        <option value="3" {eq name='$data.adv_age' value="3"}selected{/eq}>55以上</option>
                        <option value="4" {eq name='$data.adv_age' value="4"}selected{/eq}>全部年龄段</option>
                    </select>
                </div>
            </div>
            <div class="form-group place">
                <label class="col-sm-3 control-label">投放时长</label>
                <div class="col-sm-5">
                    <input type="text"  class="form-control" value="{$data.adv_time_length}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">广告分类</label>
                <div class="col-sm-5">
                    <select class="SearchForm form-control" name="region_name" style="width:200px;height:32px;">
                        {volist name="$info" id="vo"}
                        <option value="{$vo.region_id}"  {eq name='$data.adv_type' value="$vo.region_id"}selected{/eq} >{$vo.region_name}</option>
                        {/volist}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">广告标题</label>
                <div class="col-sm-5" style="width:300px;height:32px;">
                    <input type="text"  class="form-control" name="adv_title" value="{$data.adv_title}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">广告内容</label>
                <div class="col-sm-5" >
                    <textarea class="form-control" rows="7" name="adv_content" style="width:400px;">{$data.adv_content}</textarea>
                </div>
            </div>
            <div class="form-group">
            <label class="col-sm-3 control-label">上传轮播图</label>
            <div class="col-sm-5">
                <a href="javascript:;" class="file file1">选择文件
                    <input type="file" name="fileZ" id="file1" onchange="aaaa(this);">
                </a><span style="position:relative;bottom:10px;left:5px;">(建议尺寸370×180)</span>
            </div>
        </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">预览图</label>
                <div class="col-sm-3 file1_1" id="androimg" style="float:left">
                    <img src="{$data.adv_banner_img}" alt="" width="370" height="180" >
                </div>
            </div>
            <!--编辑6张详情图start-->
            <div class="form-group">
                <label class="col-sm-3 control-label">详情图片</label>
                <div class="col-sm-8 mww_last_image">
                    {volist name='for_loop' id='loop'}
                    <a href="javascript:;" class="file file{$loop}" {if $next == $loop} style="display: inline-block;" {else} style="display: none;" {/if}>选择文件
                    <input onchange="ddddd(this);" type="file" name="thumb{$loop}" class="{$loop}" style="float:left" {if in_array($loop,$sixhave)} data-param="1" {else} data-param="0" {/if}>
                    </a>
                    {/volist}
                </div>
            </div>
            <div style="clear: both;width: 100%;height: 1px;"></div>
            <div class="form-group">
                <label class="col-sm-3 control-label">预览图</label>
                {volist name='for_loop' id='loop'}
                <div id="androimg{$loop}" style="float:left;width:80px;height: 80px;margin-left:10px">
                    {if in_array($loop,$sixhave)}
                    <img class="mww_up{$loop}" src="{$sixsrc[$loop]}" height="80" width="80" onmouseover="mww_over(this);" onmouseout="mww_out(this);" />
                    <div id="d{$sixid[$loop]}" onmouseout="mww_out(this);" onmouseover="mww_over(this);" onclick="mww_click(this);" class="mww_del{$loop}" style="position: relative;top: 0;height: 20px;width: 100%;line-height: 20px;text-align: center;background-color: gray;cursor: pointer;color: #FFF;display: none;">删除</div>
                    {/if}
                </div>
                {/volist}
            </div>
            <div style="height: 20px;"></div>
            <div id="last_checkbox" style="display: none;">
                {volist name='sixhave' id='have'}
                <input type="checkbox" checked name="insert_image[]" value="{$sixsrc[$have]}" id="a{$sixid[$have]}" />
                {/volist}
            </div>
            <input type="hidden" name="who" id="who" value="">
            <!--判断属性：到6个改为0，不到6个改成1-->
            {if $isten>9}
            <input type="hidden" id="isten" value="0" />
            {else}
            <input type="hidden" id="isten" value="1" />
            {/if}
            <!--编辑6张详情图end-->
            <div style="height: 20px;"></div>
            <div class="form-group">
                <label class="col-sm-3 control-label">发布位置</label>
                <div class="col-sm-5">
                    <input type="text"  class="form-control" name="citare" value="{$cit}--{$are}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">广告数</label>
                <div class="col-sm-5">
                    <input type="text"  class="form-control" value="{$data.adv_red_count_total}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">单个广告费用</label>
                <div class="col-sm-5">
                    <input type="text"  class="form-control"value="￥{$data.adv_single_money}" readonly>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">支付金额</label>
                <div class="col-sm-5">
                    <input type="text"  class="form-control" value="￥{$data.adv_total_money}" readonly>
                </div>
            </div>
        </fieldset>
    </form>
</div>

<script>
    $(function () {
        $.ajax({
            url: 'super/Life/province',
            type: 'POST',
            dataType: 'json',//返回的数据类型
            success:function (data) {
                $("#province").html("");
                var html = " <option value=''>不限</option>";
                $.each(data, function (i, item) {
                    html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
                });
                $("#province").append(html);

            }
        })
    })
    $("#province").on("change",function () {
        var city = $("#province").val();
        $("#area").html("");
        var html = " <option value=''>不限</option>";
        $("#area").append(html);

        getCity(city);
    })
    $("#city").on("change",function () {
        var city = $("#city").val();
        getArea(city);
    })
    function getCity(city){
        $.ajax({
            url: 'super/Life/city',
            data: {city: city},
            type: 'POST',
            dataType: 'json',//返回的数据类型
            success: function (data) {
                var cityArray =  data.cityArray;
                $("#city").html("");
                var html = " <option value=''>不限</option>";
                $.each(cityArray, function (i, item) {
                    html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
                });
                $("#city").append(html);
            }
        })
    }

    function getArea(area){
        $.ajax({
            url: 'super/Life/area',
            data: {area: area},
            type: 'POST',
            dataType: 'json',//返回的数据类型
            success: function (data) {
                var cityArray =  data.cityArray;
                $("#area").html("");
                var html = " <option value=''>不限</option>";
                $.each(cityArray, function (i, item) {
                    html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
                });
                $("#area").append(html);
            }
        })
    }

    $().ready(function(){
        if($("#style").val()==2){
            $('.place').css('display','');
        }
        if($("#region").val()==2 && $("#acity").val()=='' && $("#adistrict").val()==''){
            $('.drop').css('display','');
        }
    })
    $('#style').change(function(){
        if($(this).val()==2){
            $('.place').css('display','');
            if($('#region').val()==2 && $("#acity").val()=='' && $("#adistrict").val()==''){
                $('.drop').css('display','');
            }
        }else{
            $('.place').css('display','none');
            $('.drop').css('display','none');
        }
    })
    $('#region').change(function(){
        if($(this).val()==2 && $("#acity").val()=='' && $("#adistrict").val()==''){
            $('.drop').css('display','');
        }else{
            $('.drop').css('display','none');
        }
    })

    /*轮播图*/
    function aaaa(file) {
        var prevDiv = document.getElementById('androimg');
        // console.log(file.files);
        if (file.files && file.files[0])
        {
            var reader = new FileReader();
            reader.onload = function(evt){
                prevDiv.innerHTML = '<img src="' + evt.target.result + '" height="180" width="370"/>';
            }
            reader.readAsDataURL(file.files[0]);
        }
        else
        {
            prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';
        }
    }
    //==详情6张图==============================================
    function ddddd(file) {
        var all = 1;
        var nothing = 1;
        var eq = 0;
        var classname = 0;
        $('.mww_last_image input').each(function (index,data) {
            var param = $(this).attr('data-param');
            if(param == 0){
                if(nothing == 1){
                    classname = data.className;
                    eq = index;
                    $('#who').val(classname);
                }
                nothing++;
            }else{
                all++;
            }
        });
        var ten = $('#isten').val();
        if(ten == 0){
            alert('最多只能选择6张');
            return;
        }
        var prevDiv = document.getElementById('androimg'+classname);
        if (file.files && file.files[0])
        {
//            start-把图片上传到后台
            var formData = new FormData($( "#updateForm" )[0]);//addForm是表单的id，不是input file的
            $.ajax({
                url: 'super/Advert/insertAdvPic',
                data: formData,
                type: 'POST',
                async: false,//1，这四个要写上，否则点击没反应
                cache: false,//2
                contentType: false,//3
                processData: false,//4
                dataType: 'JSON',
                success: function (returnData) {
                    if(returnData.status==200){
                        $('#androimg'+classname).css('display','block');
                        $('#last_checkbox').append('<input type="checkbox" checked name="insert_image[]" value="'+returnData.msg+'" id="a'+returnData.idid+'" />');
                        var newclassname = 0;
                        var newnothing = 1;
                        $('.mww_last_image input').eq(eq).attr('data-param',1);
                        $('.mww_last_image input').each(function (index,data) {
                            var param = $(this).attr('data-param');
                            if(param == 0){
                                if(newnothing == 1){
                                    newclassname = data.className;
                                }
                                newnothing++;
                            }
                        });
                        if(all < 6){
                            $(".file"+newclassname).show();
                            $(".file"+newclassname).siblings().hide();
                        }else{
                            $('#isten').val(0);
                        }
                        var reader = new FileReader();
                        reader.onload = function(evt){
                            prevDiv.innerHTML = '<img class="mww_up'+classname+'" src="' + evt.target.result + '" height="80" width="80" onmouseover="mww_over(this);" onmouseout="mww_out(this);" />'+
                                '<div id="d'+returnData.idid+'" onmouseout="mww_out(this);" onmouseover="mww_over(this);" onclick="mww_click(this);" class="mww_del'+classname+'" style="position: relative;top: 0;height: 20px;width: 100%;line-height: 20px;text-align: center;background-color: gray;cursor: pointer;color: #FFF;display: none;">删除</div>';
                        };
                        reader.readAsDataURL(file.files[0]);
                    }else{
                        alert(returnData.msg);
                    }

                },
                error: function () {
                    alert(returnData.msg);
                }
            });
//            end-把图片上传到后台=
        }
        else
        {
            prevDiv.innerHTML = '<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>';

        }
    }
    //=========6张图end=====================

    function mww_over(self) {
        var cln = self.className;
        var num = cln.substr(cln.length-1,1);
        $('.mww_del'+num).show();
    }
    function mww_out(self) {
        var cln = self.className;
        var num = cln.substr(cln.length-1,1);
        $('.mww_del'+num).hide();
    }
    function mww_click(self) {
        var cln = self.className;
        var num = cln.substr(cln.length-1,1);
        var id = self.id;
        var idid = id.substr(1,id.length-1);
        $('.file'+num+' input').attr('data-param',0);
        $('#isten').val(1);
        $('#androimg'+num).html('');
        $('#androimg'+num).css('display','none');
        $('#a'+idid).remove();
        var newclassname = 0;
        var newnothing = 1;
        $('.mww_last_image input').each(function (index,data) {
            var param = $(this).attr('data-param');
            if(param == 0){
                if(newnothing == 1){
                    newclassname = data.className;
                }
                newnothing++;
            }
        });
        $(".file"+newclassname).show();
        $(".file"+newclassname).siblings().hide();
    }



    $(".template").on('change',function () {
        var template_val = $(this).val();
        if(template_val==1||template_val==3){
            $(".file1").show();
            $("#androimg").show();
            $(".file2,.file3").hide();
            $("#androimg1,#androimg2").hide();
        }else if(template_val==2){
            $(".file2,.file1,.file3").show();
            $("#androimg0,#androimg1,#androimg2").show();
        }
    });
</script>